<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 13-11-8
 * Time: 上午9:50
 * 显示票付通会员列表
 */
use \PFT\Db;
if ($_SESSION['memberID'] != 1 && !($_SESSION['sid'] == 1 && strpos($_SESSION['qx'], 'wx'))) {
    exit("不合法的身份访问！");
    //exit("<script>window.location='dlogin.html'</script>");
}
include '../common/autoload.php';
include COMMONPATH.'page.php';
include_once '/var/www/html/new/d/module/common/Db.class.php';
$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息
Db::Conf($dbConf['remote_1']);


$currentPage =$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize    =$_REQUEST["pageSize"]?$_REQUEST["pageSize"]:10;
$offset     =($currentPage-1)*$pageSize;


$sql = <<<SQL
SELECT `id`,`fid`, `nick_name`, `user_name`, `appid`, `service_type_info`,
 `verify_type_info`, `head_img`, `qrcode_url`, `isconnect`,
 `func_info`, `authorizer_refresh_token`,create_time,chk_status FROM pft_wx_open
SQL;
$where = ' WHERE 1=1';
if ($_GET['nick_name']) {
    $where  .=" AND nick_name like '%{$_GET['nick_name']}%'";
}

if ($_GET['fid']) {
    $fid = intval($_GET['fid']);
    $where .=" AND fid=$fid";
}
if (isset($_GET['status'])) {
    $status = intval($_GET['status']);
    $where .= " AND isconnect=$status";
} else {
    $where .= " AND isconnect<>2";
}

$sql_limit .= " order by ID desc LIMIT $offset,$pageSize";

$sql .= $where.$sql_limit;
//echo $sql;
$stmt = Db::Connect()->prepare($sql);
$stmt->execute();
$mem_list = $stmt->fetchAll(PDO::FETCH_ASSOC);

$connectList = array(
    0 => '<span style="color:green;font-weight: bold;">已授权</span>',
    1 => '<span style="color:red">已取消授权</span>',
    2 => '<span style="color:gray">删除</span>',
);

$service_type_info = array(
    0=>'订阅号', 1=>'升级后的订阅号',2=>'服务号',
);
//授权方认证类型
$verify_type_info = array(
    -1 => '未认证',
    0 => '微信认证',
    1 => '新浪微博认证',
    2 => '腾讯微博认证',
    3 => '已资质认证通过但还未通过名称认证',
    4 => '已资质认证通过,',
    5 => '已资质认证通过',
);
/*，-1代表未认证，0代表微信认证，1代表新浪微博认证，2代表腾讯微博认证，3代表已资质认证通过但还未通过名称认证，
4代表已资质认证通过、还未通过名称认证，但通过了新浪微博认证，5代表已资质认证通过、还未通过名称认证，但通过了腾讯微博认证*/

$sql_total = "SELECT COUNT(*) as total FROM pft_wx_open $where";
$stmt = Db::Connect()->prepare($sql_total);
$stmt->execute();
$total_rows = $stmt->fetchColumn(0);

if ($_SERVER['REQUEST_METHOD']=='POST' && $_POST['action']=='chk_status') {
    $id  = intval($_POST['id']);
    $val = strtoupper(trim($_POST['val']));
    $sql = "UPDATE pft_wx_open SET chk_status='$val' WHERE id=$id LIMIT 1";
    if (Db::Connect()->exec($sql)) {
        echo 1;
    } else {
        echo 0;
    }
    exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script language="javascript" src="/js/jquery-1.8.0.min.js"></script>
    <title>微信账号绑定列表 - 票付通分销平台</title>
    <style>
        .wx-head-img{width: 40px;}
        .wx-img{
            width:90px;
        }
    </style>
</head>
<body>
<link rel="stylesheet" href="/css/aliceui.min.css"/>
<link rel="stylesheet" href="/css/resetui.css"/>
<link rel="stylesheet" href="/css/page.css"/>
<link rel="stylesheet" href="css/list.css"/>
<link rel="stylesheet" href="//www.16u.com/manage/admin/css/dialog.css"/>
<div class="wrap">
    <form name="ourform" class="search_form ">
        <input name="dev" value="<?=$_GET['dev']?>" type="hidden"/>
        <fieldset class="search-box">
            <legend>查询</legend>
            <table class="search-tbl" cellspacing="0">
                <tr>
                    <!--<td>
                    <label class="t">审核状态</label>
                    <select name="status">
                        <option value="-1" <?=!isset($_GET['status']) || $_GET['status']==-1? 'selected':'';?>>--不限--</option>
                        <option value="0" <?=isset($_GET['status']) && $_GET['status']==0? 'selected':'';?>>未审核</option>
                        <option value="1" <?=$_GET['status']==1? 'selected':'';?>>正常</option>
                        <option value="2" <?=$_GET['status']==2? 'selected':'';?>>拒绝</option>
                    </select>
                </td>-->
                    <td>
                        公众号名称:<input name="nick_name" value="<?=$_GET['nick_name']?>"/>
                    </td>
                    <td>
                        账号ID:<input name="fid" value="<?=$_GET['fid']?>"/>
                    </td>
                    <td>
                        状态: <select name="status">
                            <option value="0"
                                <?=$_GET['status']==0 ? 'selected':''?> >已接入</option>
                            <option value="1"
                                <?=$_GET['status']==1 ? 'selected':''?> >未接入</option>
                            <option value="2"
                                <?=$_GET['status']==2 ? 'selected':''?> >删除</option>
                        </select>
                    </td>
                    <td>
                        <button id="searchBtn" type="submit" class="ui-button ui-button-lorange">查　找</button>
                    </td>
                </tr>
            </table>
        </fieldset>
    </form>
    <div class="ui-table-container">
        <table class="ui-table ui-table-noborder"><!-- 可以在class中加入ui-table-inbox或ui-table-noborder分别适应不同的情况 -->
            <thead>
            <tr>
                <th style="width: 80px;">接入时间</th>
                <th>会员ID</th>
                <th>公众号名称</th>
                <th>公众号原始ID</th>
                <th>APPID</th>
                <th>公众号类型</th>
                <th>认证类型</th>
<!--                <th>头像</th>-->
                <th>二维码</th>
                <th>菜单权限</th>
                <th>网页授权权限</th>
                <th>是否接入</th>
                <th>是否审核</th>
                <?php if($_GET['dev']):?>
                    <th>刷新令牌</th>
                <?php endif;?>
            </tr>
            </thead>
            <tbody id="tao_list_tbd">
            <? foreach($mem_list as $list): ?>
                <tr id="tr_<?=$list['id']?>">
                    <td><?=$list['create_time']?></td>
<!--                    <td>--><?//=$list['id']?><!--</td>-->
                    <td><?=$list['fid']?></td>
                    <td>
                        <img src="<?=$list['head_img']?>" class="wx-head-img" >
                        <br/><?=$list['nick_name']?>
                    </td>
                    <td><?=$list['user_name']?></td>
                    <td><?=$list['appid']?></td>
                    <td><?=$service_type_info[$list['service_type_info']]?></td>
                    <td><?=$verify_type_info[$list['verify_type_info']]?></td>
<!--                    <td><img src="--><?//=$list['head_img']?><!--" class="wx-img" ></td>-->
                    <td><a title="新窗口打开" href="<?=$list['qrcode_url']?>" target="_blank"><img src="<?=$list['qrcode_url']?>" class="wx-img" ></a></td>
                    <td><?=(in_array(1, explode(',', $list['func_info'])) ? '是' :'否')?></td>
                    <td><?=(in_array(3, explode(',', $list['func_info'])) ? '是' :'否')?></td>
                    <td><?=$connectList[$list['isconnect']]?></td>
                    <td data-id="<?=$list['id']?>">
                        <p><label><input <?=$list['chk_status']=='N'?'checked':''?> type="radio" name="chk_status[<?=$list['id']?>]" value="N"/>否</label></p>
                        <p><label><input <?=$list['chk_status']=='Y'?'checked':''?> type="radio" name="chk_status[<?=$list['id']?>]" value="Y"/>是</label></p>
                    </td>
                    <?php if($_GET['dev']):?>
                    <td><?=$list['authorizer_refresh_token']?></td>
                    <?php endif;?>
                </tr>
            <? endforeach; ?>
            </tbody>
        </table>
        <?page($total_rows,$currentPage,$pageSize);?>
    </div>
</div>
<script>
    $(document).ready(function(){
        $("#tao_list_tbd").on('click', 'input:radio', function(){
            var id = $(this).parents('td').data('id'),
                val = $(this).val();
            if (!confirm('确定要执行此操作吗？')) return false;
            $.post('wx_dev.php', {id:id, val:val,action:'chk_status'}, function(res){
                if (res==1) alert('操作成功刷新页面可查看效果');
                else alert('操作失败啦！');
            });
        });
    });
</script>
</body>
</html>
